<%@ page language="java" contentType="text/html;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>登录信息页面</title>
<style>
body {
	background-image:url(images/asuka&ayanami.jpg);
	background-size: 100%;
}
table{
	color: purple;
	background-color: rgba(200,200,0,0.1);
}
</style>
</head>
<body>
	<div>
		<form action="login/getLoginMsg.action" id="form1" method="POST" >
		<input type="hidden" name="page" value="${page }" id="hidden_page"/>
		<input type="hidden" name="pages" value="${pages }" id="hidden_pages"/>
		<input type="hidden" name="order" value="${order }" id="hidden_order"/>
		<input type="hidden" name="desc" value="${desc }" id="hidden_desc"/>
		<table border="1">
			<tr>
				<th onclick="order('sIp')">IP地址</th><th colspan="5" onclick="order('dtLoginTime')">登陆时间</th>
			</tr>
		<c:forEach items="${ipList }" var="item">
			<tr>
				<td>${item.sIp}</td>
				<td colspan="5" >${item.dtLoginTime}</td>
			</tr>
		</c:forEach>
			<tr>
				<td><a href="javascript:;" onclick="toPage('last')">上一页</a></td>
				<td><span>第${page}/${pages}页</span></td>
				<td><input type="text" pattern="\w{1,${pages}}" style="width:50px" id="text_page" title="填写不合法"/></td>
				<td><input type="button" value="跳转" onclick="toPage('text')"/></td>
				<td>
					<select id="select" onchange="toPage('select')">
						<c:forEach var="item" begin="1" end="${pages}">
							<option value="${item}" 
								<c:if test="${item == page}">
									selected="selected"
								</c:if>
							/>第 ${item} 页
						</c:forEach>
					</select>
				</td>
				<td><a href="javascript:;" onclick="toPage('next')">下一页</a></td>
			</tr>
		</table>
		</form>
	</div>
</body>
<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
<script type="text/javascript">
	function toPage(str){
		var page = $("#hidden_page").val();
		var pages = $("#hidden_pages").val();
		if (page == "") {
			page = 1;
		} else {
			page = parseInt(page);
		}
		if (str == "last") {
			page -= 1;
		} else if (str == "next") {
			if(page<pages){
				page = page + 1;
			}
		} else if (str == "text") {
			page = $("#text_page").val();
			if ("" == page) {
				alert("请填写页数！");
				return false;
			}
			try {
				page = parseInt(page);
			} catch (e) {
				return false;
			}
			if(page>=pages){
				page=pages;
			}
		} else if(str == "select"){
			page = $("#select").val();
		}
		else {
			return false;
		}
		$("#hidden_page").val(page);
		document.getElementById("form1").submit();
	}
	function order(str){
		var order = $("#hidden_order").val();
		var desc = $("#hidden_desc").val();
		if(str == "sIp"){
			order = "sIp";
			if(desc=="desc"){
				desc="asc";
			}else{
				desc="desc";
			}
		}else if(str == "dtLoginTime"){
			order = "dtLoginTime";
			if(desc=="desc"){
				desc="asc";
			}else{
				desc="desc";
			}
		}
		$("#hidden_order").val(order);
		$("#hidden_desc").val(desc);
		document.getElementById("form1").submit();
	}
</script>
</html>